$data.Entity.extend('Question', {
	id: { type: 'int', key: true,required: true },	
	type: { type: 'int',required: true },
	text: { type: 'string',required: true },
	indication: { type: 'string'},
	solution: { type: 'string'},
	qcm_id: { type: 'int',required: true}	
});

function getValueQuestions(BD,champs,valeur){
	return BD.Questions.filter('it.'+champs+' == '+valeur).toArray();
}

function getValueQuestionsAndReponses(BD,champs,valeur){
	
	return $.when(BD.Questions.filter('it.'+champs+' == '+valeur).toArray()).then(function(questions){
		var listeReponses = [];		
		var listeQuestions = [];	
		
		questions.forEach(function(question){
			listeReponses.push(getValueReponses(BD,'question_id',question.id));			
			listeQuestions.push(question);			
		});
		
		if(listeQuestions.length == 0){			
			return listeQuestions;
		}
		
		return $.when.apply($, listeReponses).then(function(){
			
			for( var i = 0; i < arguments.length; i++ ) {
				listeQuestions[i].reponses =  arguments[i];
			}

			return listeQuestions;
		});
	});
}